package com.example.myapplication.lawyer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.LawyerconsultationtBean;
import com.example.myapplication.ShuJu.LawyerdetailsBean;

public class IDLawyerconsultationtActivity extends AppCompatActivity {

    private String lawyerconsultationtActivityID;
    private String LawyerconsultationtActivityLawyerId;
    private TextView text_status;
    private TextView text_type;
    private TextView text_content;
    private TextView text_iphone;
    private LinearLayout li_submit;
    private ImageView img_topchoicelawyy;
    private TextView text_topchoicelawyy;
    private TextView year_topchoicelawyy;
    private TextView num_topchoicelawyy;
    private TextView name_topchoicelawyy;
    private ImageView but_topchoicelawyy;
    private  String TAG = "TAG" ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.idactivity_lawyerconsultationt);
        initview();
        //获取律师问题详情
        getLawyerconsultationt();
        //获取律师详情
        lawyerdetails();
        //返回
        but_bloak();
        //服务评论页
        servicecomment();
    }

    private void servicecomment() {
        li_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(IDLawyerconsultationtActivity.this,ServicecommenttActivity.class);
                intent.putExtra("serviceID",lawyerconsultationtActivityID);
                IDLawyerconsultationtActivity.this.startActivity(intent);
            }
        });
    }

    private void but_bloak() {
        but_topchoicelawyy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IDLawyerconsultationtActivity.this.finish();
            }
        });
    }

    private void lawyerdetails() {
        OKHttpTool.doNetRequest("prod-api/api/lawyer-consultation/lawyer/" + LawyerconsultationtActivityLawyerId,
                OKHttpTool.GET,
                LawyerdetailsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        LawyerdetailsBean lawyerdetailsBean = (LawyerdetailsBean) obj;
                        if (lawyerdetailsBean.getCode() == 200) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    LawyerdetailsBean.DataBean  data = lawyerdetailsBean.getData();
                                    Glide.with(IDLawyerconsultationtActivity.this).load(TokenBean.IP + data.getAvatarUrl()).into(img_topchoicelawyy);
                                    name_topchoicelawyy.setText(data.getName());
                                    text_topchoicelawyy.setText(data.getLegalExpertiseName());
                                    year_topchoicelawyy.setText(data.getWorkStartAt());
                                    num_topchoicelawyy.setText(String.valueOf(data.getServiceTimes()));

                                }
                            });
                        }
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void getLawyerconsultationt() {
        OKHttpTool.doNetRequest("/prod-api/api/lawyer-consultation/legal-advice/" + lawyerconsultationtActivityID,
                OKHttpTool.GET,
                LawyerconsultationtBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                LawyerconsultationtBean lawyerconsultationtBean = (LawyerconsultationtBean) obj;
                                if (lawyerconsultationtBean.getCode() == 200) {
                                    String legalExpertiseName = lawyerconsultationtBean.getData().getLegalExpertiseName();
                                    String Content = lawyerconsultationtBean.getData().getContent();
                                    String phone = lawyerconsultationtBean.getData().getPhone();
                                    String state = lawyerconsultationtBean.getData().getState();
                                    //lawyerconsultationtBean.getData().setState("1");
                                    if (!TextUtils.isEmpty(legalExpertiseName)) {
                                        text_type.setText(legalExpertiseName);
                                    }
                                    if (!TextUtils.isEmpty(Content)) {
                                        text_content.setText(Content);
                                    }
                                    if (!TextUtils.isEmpty(phone)) {
                                        text_iphone.setText(phone);
                                    }
                                    if (!TextUtils.isEmpty(state) && "0".equals(lawyerconsultationtBean.getData().getState())) {
                                        text_status.setText("未处理");
                                    } else if (!TextUtils.isEmpty(state) && "1".equals(lawyerconsultationtBean.getData().getState())) {
                                        text_status.setText("已处理");
                                    }
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initview() {
        Intent intent = getIntent();
        //律师咨询ID
        lawyerconsultationtActivityID = intent.getStringExtra("LawyerconsultationtActivityID");
        Log.e(TAG,"lawyerconsultationtActivityID==>"+lawyerconsultationtActivityID);
        //律师ID
        LawyerconsultationtActivityLawyerId = intent.getStringExtra("LawyerconsultationtActivityLawyerId");

        but_topchoicelawyy = findViewById(R.id.but_topchoicelawyy);
        img_topchoicelawyy = findViewById(R.id.img_topchoicelawyy);
        text_topchoicelawyy = findViewById(R.id.text_topchoicelawyy);
        year_topchoicelawyy = findViewById(R.id.year_topchoicelawyy);
        num_topchoicelawyy = findViewById(R.id.num_topchoicelawyy);
        name_topchoicelawyy = findViewById(R.id.Name_topchoicelawyy);


        text_status = findViewById(R.id.text_status);
        text_type = findViewById(R.id.text_type);
        text_content = findViewById(R.id.text_content);
        text_iphone = findViewById(R.id.text_iphone);
        li_submit = findViewById(R.id.li_submit);
    }
}